using System.Collections.Generic;
using System.Linq;

namespace PokerStar.Core.Rules
{
    public interface IRule
    {
        IRule Next { get; }
        GameResult Test(RuleContext context);
    }

    public class RuleContext
    {
        public RuleContext(IList<Card> cards)
        {
            Ordinal = cards;
            GroupByNumber = cards.GroupBy(p => p.Number).
                                  OrderByDescending(p => p.Count()).
                                  ThenByDescending(p => CardNumberComparer.Card2Int(p.First().Number)).
                                  ToArray();
            GroupBySuit = cards.GroupBy(p => p.Suit).
                                OrderByDescending(p => p.Count()).
                                ToArray();
        }

        public IList<Card> Ordinal { get; private set; }
        public IGrouping<Suit, Card>[] GroupBySuit { get; private set; }
        public IGrouping<char, Card>[] GroupByNumber { get; private set; }
    }
}